{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "OwadPvvajoS9"
   },
   "outputs": [],
   "source": [
    "class PrimesBelow:\n",
    "    def __init__(self, bound):\n",
    "        self.candidate_numbers = list(range(2,bound))\n",
    "    def __iter__(self):\n",
    "        return self\n",
    "    def __next__(self):\n",
    "        if len(self.candidate_numbers) == 0:\n",
    "            raise StopIteration\n",
    "        next_prime = self.candidate_numbers[0]\n",
    "        self.candidate_numbers = [x for x in self.candidate_numbers if x % next_prime != 0]\n",
    "        return next_prime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "Iz0LI12Iju16",
    "outputId": "31ff3be9-9b70-4f57-aa52-3310e14f87b0"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\n"
     ]
    }
   ],
   "source": [
    "primes_to_a_hundred = [prime for prime in PrimesBelow(100)]\n",
    "print(primes_to_a_hundred)"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "name": "Exercise07.ipynb",
   "provenance": [],
   "version": "0.3.2"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
